#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

class Score
{
    string name;
    int mark;

public:
    Score() : mark(0) {}
    Score(string _name, int _mark)
        : name(_name), mark(_mark) {}
    string getName() { return name; }
    int getMark() { return mark; }
    void scan()
    {
        cin >> name >> mark;
    }
};

class Student
{
    string name;
    map<string, int> mScore;

public:
    string getName() { return name; }
    void scan();
    set<string> getCourseNames();
    int getMarkByCourseName(string courseName);
};

class Department
{
    vector<Student> vStudent;

public:
    void scan()
    {
        int number;
        cin >> number;
        for (int i = 0; i < number; i++)
        {
            Student stu;
            stu.scan();
            vStudent.push_back(stu);
        }
    }
    void report();
};

//  -----
//  Your code goes here:

int Student::getMarkByCourseName(string coursename)
{
    map<string, int>::iterator it;
    it = mScore.find(coursename);
    if (it != mScore.end())
        return mScore[coursename];
    else
        return -1;
}

set<string> Student::getCourseNames()
{
    set<string> course_set;
    for (map<string, int>::iterator iter = mScore.begin(); iter != mScore.end(); iter++)
    {
        course_set.insert(iter->first);
    }
    return course_set;
}

void Student::scan() // read name, courses and score
{
    getline(cin, name);
    getline(cin, name);
    int num; // number of courses
    cin >> num;
    double ave = 0;
    for (int i = 0; i < num; i++)
    {
        string str;
        cin >> str;
        int score;
        cin >> score;
        ave = ave + score;
        mScore[str] = score;
    }
    ave = ave / num;
    // cout << ave << endl;
    mScore["average"] = ave;
}
#include <cmath>
void Department::report()
{
    set<string> course_list;
    vector<double> average;
    vector<int> cnts;
    int c = vStudent.size();
    for (int i = 0; i < c; i++)
    {
        set<string> tmp = vStudent[i].getCourseNames(); // Question!!!
        for (set<string>::iterator iter = tmp.begin(); iter != tmp.end(); iter++)
        {
            course_list.insert(*iter);
            // cout << "fk" << endl;
        }
    }
    int c2 = course_list.size();
    for (int i = 0; i < c2; i++)
    {
        average.push_back(0);
        cnts.push_back(0);
    }

    cout << "name"
         << "\t"
         << "\t";
    for (set<string>::iterator iter = course_list.begin(); iter != course_list.end(); iter++)
    {
        if (*iter != "average")
            cout << *iter << "\t";
        else
            cout << *iter;
    }
    cout << endl;

    for (int i = 0; i < c; i++)
    {
        int cnt = 0;
        cout << vStudent[i].getName() << "\t";
        for (set<string>::iterator iter = course_list.begin(); iter != course_list.end(); iter++)
        {

            if (vStudent[i].getMarkByCourseName(*iter) != -1) // 有课
            {
                if (*iter != "average")
                    cout << vStudent[i].getMarkByCourseName(*iter) << "\t";
                else
                    cout << vStudent[i].getMarkByCourseName(*iter);
                average[cnt] += vStudent[i].getMarkByCourseName(*iter);
                cnts[cnt]++;
            }
            else
                cout << "-"
                     << "\t";
            cnt++;
            // cout << "nihao" << endl;
        }
        cout << endl;
    }

    cout << "\t"
         << "\t";
    for (int i = 0; i < c2 - 1; i++)
    {
        average[i] = average[i] / cnts[i];
        cout << round(average[i]) << "\t";
    }
}
//  -----

int main()
{
    Department dept;
    dept.scan();
    dept.report();
    return 0;
}

/* 请在这里填写答案 */
